package com.ymttest.business.service.YMTTrading;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;

import com.ymatou.iapi.optrade.parameter.enums.CouponApplianceTypeEnum;
import com.ymatou.iapi.optrade.parameter.vo.CouponVo;
import com.ymttest.business.service.CouponServiceMCallService;
import com.ymttest.business.service.CouponServiceMCallServiceV2;

/**
 * 洋码头订单促销创建类
 * @author cszhangyi
 *
 */
public class TradingAllPromotion {

	// 是否为新优惠券服务
	public static final boolean IS_NEW_COUPON_SERVER = true;
	
	/**
	 * 
	 * @param userId
	 *            用户买家id
	 * @param sellerId
	 *            商家卖家id
	 * @param orderAmount
	 *            订单满多少
	 * @param sellerCouponValue
	 *            优惠券减多少
	 * @return CouponVo
	 */
	public static CouponVo createSellerCouponVo(Long userId, Long sellerId,
			BigDecimal orderAmount, BigDecimal sellerCouponValue) {

		String sellerCouponCode = TradingAllPromotion.receiveSellerCoupon(
				userId, sellerId, orderAmount, sellerCouponValue);

		if (StringUtils.isEmpty(sellerCouponCode)) {
			return null;
		}

		return createCouponVo(sellerCouponCode, sellerCouponValue);
	}

	/**
	 * 
	 * @param userId
	 *            用户买家id
	 * @param orderAmount
	 *            订单满多少
	 * @param ymtCouponValue
	 *            优惠券减多少
	 * @return CouponVo
	 */
	public static CouponVo createYMTCouponVo(Long userId,
			BigDecimal orderAmount, BigDecimal ymtCouponValue) {

		String ymtCouponCode = TradingAllPromotion.receiveYMTCoupon(userId,
				orderAmount, ymtCouponValue);

		if (StringUtils.isEmpty(ymtCouponCode)) {
			return null;
		}

		return createCouponVo(ymtCouponCode, ymtCouponValue);
	}

	/**
	 * createCouponVo
	 * 
	 * @return CouponVo
	 */
	public static CouponVo createCouponVo(String couponCode,
			BigDecimal couponValue) {

		CouponVo coupon = new CouponVo();

		coupon.setApplianceType(CouponApplianceTypeEnum.ALL);
		coupon.setCouponCode(couponCode);
		coupon.setCouponValue(couponValue);

		return coupon;
	}

	/**
	 * 领用商家优惠券
	 * 
	 * @param userId
	 * @param sellerId
	 * @param orderAmount
	 *            订单金额
	 * @param sellerCouponValue
	 *            优惠券减免金额
	 * @return
	 */
	public static String receiveSellerCoupon(Long userId, Long sellerId,
			BigDecimal orderAmount, BigDecimal sellerCouponValue) {

		if (IS_NEW_COUPON_SERVER) {

			return CouponServiceMCallServiceV2.receiveSellerCoupon(userId,
					sellerId, orderAmount, sellerCouponValue);
		} else {
			return CouponServiceMCallService.receiveSellerCoupon(userId,
					sellerId, orderAmount, sellerCouponValue);
		}

	}

	/**
	 * 领用YMT平台优惠券默认链接优惠券
	 * 
	 * @param userId
	 * @param orderAmount
	 * @param couponValue
	 * @return
	 */
	public static String receiveYMTCoupon(Long userId, BigDecimal orderAmount,
			BigDecimal couponValue) {

		if (IS_NEW_COUPON_SERVER) {
			return CouponServiceMCallServiceV2.receiveYMTCoupon(userId,
					orderAmount, couponValue);
		} else {
			return CouponServiceMCallService.receiveYMTCoupon(userId,
					orderAmount, couponValue);
		}
	}
}
